import QtQuick 1.0
import "Dialogs"
import "ListViews"
import "Models"
import "WebAccess/TwitterAPI.js" as TwitterAPI
import "Util/Util.js" as Util


Item {
    id: _root
    anchors.fill: parent

    MouseArea {
        id: _blankArea
        x: 0
        y: 0
        width: 0
        height: 0
        onClicked: {
            _root.state = "";
        }
    }

    //状態が変わった時の処理
    onStateChanged: {
        switch(state){
        case "Auth":
            _menuAuth.viewEvent();
            break;
        default:
            break;
        }
    }

    ///////////////////////////////
    //メインメニュー
    ListViewContext {
        id: _menuContextMenu
        x: _root.width - width - 5
        y: _actionBar.height - 5
        opacity: 0

        model: ModelContextMenu{
        }

        onClicked: {
            switch(index){
            case 0:
                //Auth
                _menuContainer.state = "Auth";
                break;
            case 1:
                //Exit
                _menuContainer.state = "ExitCaution";
                break;
            case 2:
                //About
                _menuContainer.state = "AboutCaution";
                break;
            case 3:
                break;
            default:
                break;
            }

            //メニューを消す
    //                    _menuContainer.state = "";
        }
    }

    /////////////////////////////////////
    //Auth認証のダイアログ
    DialogAuthorization {
        id: _menuAuth
        width: 200
        height: 260
        x: parent.width * 0.2
        y: parent.height * 0.2 //-(height+10)
        opacity: 0

    }


    ////////////////////
    //Timeline系のコンテキストメニュー
    ListViewContext {
        id: _menuContextTimeline
        x: adjustX(_selectItemInfo.mouse_x)
        y: adjustY(_selectItemInfo.mouse_y)
        opacity: 0

        model: ModelContextTimeline{
        }

        //クリックイベント
        onClicked: {
            //Mention
            //Retweet
            //QT
            //DM


            //メニューを消すかも
            _menuContainer.state = _contentContainer.onClickContextItem(index);
        }
    }

    //////////////////////////////////
    //User系のコンテキストメニュー
    ListViewContext {
        id: _menuContextUsers
        x: adjustX(_selectItemInfo.mouse_x)
        y: adjustY(_selectItemInfo.mouse_y)
        opacity: 0

        model: ModelContextUsers{
        }

        //クリックイベント
        onClicked: {
            //Mention
            //Retweet
            //QT
            //DM
            _contentContainer.onClickContextItem(index);

            //メニューを消す
            _menuContainer.state = "";
        }
    }

    //////////////////////////////////
    //Retweetの確認
    DialogMessage {
        id: _menuRetweetCaution
        opacity: 0
        x: (_root.width - width) / 2
        y: (_root.height - height) / 2

        dialogTitle: "Retweet"
        dialogMessage: _selectItemInfo.retweetMessage

        //OKボタンイベント
        onClickOkButton: {
            if(_selectItemInfo.itemId.length !== 0){
                TwitterAPI.sendRetweet(_selectItemInfo.itemId, null);
            }
            _root.state = "";
        }
        //キャンセルボタンイベント
        onClickCancelButton: {
            _root.state = "";
        }
    }

    ///////////////////////////////////
    //終了確認
    DialogMessage {
        id: _menuExitCaution
        opacity: 0
        x: (_root.width - width) / 2
        y: (_root.height - height) / 2

        dialogTitle: "Attention"
        dialogMessage: "Exit ?"

        //OKボタンイベント
        onClickOkButton: {
            Qt.quit();
        }
        //キャンセルボタンイベント
        onClickCancelButton: {
            _root.state = "";
        }
    }

    /////////////////////////////////////
    //バージョン情報
    DialogMessage {
        id: _menuAbout
        opacity: 0
        x: (_root.width - width) / 2
        y: (_root.height - height) / 2

        dialogTitle: "About"
        dialogMessage: "Rewit for Qt  Version " + "0.2" + "\nCopyright (C) 2011 IoriAYANE"

        visibleCancel: false

        //OKボタンイベント
        onClickOkButton: {
            _root.state = "";
        }
        //キャンセルボタンイベント
        onClickCancelButton: {
            _root.state = "";
        }
    }


    states: [
        State {
            name: "Menu"
            PropertyChanges{
                target: _menuContextMenu
                opacity: 1.0
//                y: _root.height * 0.2
            }
            PropertyChanges {
                target: _blankArea
                width: _root.width
                height: _root.height
            }
        },
        State {
            name: "MenuContextTimeline"
            PropertyChanges {
                target: _menuContextTimeline
                opacity: 1.0
            }
            PropertyChanges {
                target: _blankArea
                width: _root.width
                height: _root.height
            }
        },
        State {
            name: "MenuContextUsers"
            PropertyChanges {
                target: _menuContextUsers
                opacity: 1.0
            }
            PropertyChanges {
                target: _blankArea
                width: _root.width
                height: _root.height
            }
        },
        State {
            name: "Auth"
            PropertyChanges{
                target: _menuAuth
                opacity: 1.0
//                y: _root.height * 0.2
            }
            PropertyChanges {
                target: _blankArea
                width: _root.width
                height: _root.height
            }
        },
        State {
            name: "RetweetCaution"
            PropertyChanges{
                target: _menuRetweetCaution
                opacity: 1.0
            }
            PropertyChanges {
                target: _blankArea
                width: _root.width
                height: _root.height
            }
        },
        State {
            name: "ExitCaution"
            PropertyChanges{
                target: _menuExitCaution
                opacity: 1.0
            }
            PropertyChanges {
                target: _blankArea
                width: _root.width
                height: _root.height
            }
        },
        State {
            name: "AboutCaution"
            PropertyChanges{
                target: _menuAbout
                opacity: 1.0
            }
            PropertyChanges {
                target: _blankArea
                width: _root.width
                height: _root.height
            }
        }
    ]
    transitions: Transition {
        NumberAnimation {
            easing.type: Easing.OutCubic
            targets: [_menuContextMenu
                    , _menuContextTimeline, _menuContextUsers
                    , _menuAuth
                    , _menuRetweetCaution, _menuExitCaution
                    , _menuAbout]
            properties: "opacity"
            duration: 500
        }
    }

}
